num = input()

if len(num) != 4 or not num.isdigit():
    print(0)
else:
    max_prime = 0
    for i in range(len(num)):
        for j in range(i+1, len(num)+1):
            current_num = int(num[i:j])
            is_prime = True
            if current_num < 2:
                is_prime = False
            for k in range(2, int(current_num**0.5) + 1):
                if current_num % k == 0:
                    is_prime = False
            if is_prime and current_num > max_prime:
                max_prime = current_num

    print(max_prime)